﻿using Module_Debug.Hardware;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Ports;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace Module_Debug.Visionox_Gamma
{
    public partial class HX83200_Gamma : Form
    {
        CaSDK CaSDKObj = new CaSDK();
        CRC16 CRCData = new CRC16();
        Gamma_Addr GAMMAs = new Gamma_Addr();

        private bool Listening = false;//是否没有执行完invoke相关操作   
        private bool IClosing = false;//是否正在关闭串口，执行Application.DoEvents，并阻止再次invoke 

        private List<byte> buffer = new List<byte>(2048);//默认分配1/16页内存，并始终限制不允许超过

        private double[,] D_lums;//目标值-单色
        private double[] D_lum;//目标值-白色
        private double D_x, D_y;
        private double lum_off, x_off, y_off;
        private int index = 0;
        private int flag1 = 1; //lum
        private int flag2 = 1; //x
        private int flag3 = 1; //y
        private byte[] Send_buf = new byte[1];
        private byte[] Rec_tmp = new byte[1];

        private static bool Gamma_adjust_timeout_flag = false;
        private int adjust_Rnum = 0;
        private int adjust_Gnum = 0;
        private int adjust_Bnum = 0;
        public int adjust_l = 0;
        public int adjust_x = 0;
        public int adjust_y = 0;
        private int step_l = 1;
        //private int step_m = 5;
        private int step_h = 12;

        //监听HX83200挂载
        frmMain frmHelp = null;
        public HX83200_Gamma(frmMain HX83200)
        {
            frmHelp = HX83200;
            InitializeComponent();
            frmHelp.T20.Interval = 200; //采样周期设定
            frmHelp.T20.Tick += new EventHandler(HX83200_auto_gamma);
            Thread.Sleep(5);
            frmHelp.Child_window_hide_already = true;
            frmHelp.Child_Gamma_Window_Open_Enable = false;//防止重复开启子窗体  
        }  //publi
        //HX83200 监听卸载
        private void HX83200_Gamma_FormClosed(object sender, FormClosedEventArgs e)
        {
            //frmHelp.comPort.Close()
            Thread.Sleep(5);
            frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(HX83200_DataReceived);
            Thread.Sleep(5);
            frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);
            Thread.Sleep(5);
            //frmHelp.comPort.Open();

            frmHelp.T20.Tick -= new EventHandler(HX83200_auto_gamma);
            Thread.Sleep(5);
            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "HX83200_Gamma_FormClosed！\r\n";
            frmHelp.Child_Gamma_Window_Open_Enable = true; //允许其他子窗体打开
            frmHelp.Child_window_hide_already = false;
            frmHelp.IC_comboBox.Enabled = true;
        }

        private void HX83200_Gamma_VisibleChanged(object sender, EventArgs e)
        {
            if (frmHelp.Child_window_hide_already == false) //子窗体已开启标识
            {
                //frmHelp.comPort.Close()
                Thread.Sleep(5);
                frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(HX83200_DataReceived);
                Thread.Sleep(5);
                frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);
                Thread.Sleep(5);
                //frmHelp.comPort.Open();
                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "HX83200_Gamma_FormHide！\r\n";
                frmHelp.Child_window_hide_already = true; //子窗体已隐藏标识
            }
            else
            {
                frmHelp.comPort.DataReceived -= new SerialDataReceivedEventHandler(frmHelp.SerialPort1_DataReceived);
                Thread.Sleep(5);
                frmHelp.comPort.DataReceived += new SerialDataReceivedEventHandler(HX83200_DataReceived);
                Thread.Sleep(5);
                frmHelp.T20.Tick += new EventHandler(HX83200_auto_gamma);
                Thread.Sleep(5);
                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "HX83200_Gamma_FormOpened！\r\n";
                frmHelp.Child_window_hide_already = false; //子窗体已开启标识
            }
        }


        //串口接收
        private void HX83200_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)//Getting data from Comm Port
        {
            if (IClosing) return;
            try
            {
                Listening = true;//设置标记，说明我已经开始处理数据，一会儿要使用系统UI的。         
                int n = frmHelp.comPort.BytesToRead;
                byte[] buf = new byte[n];
                byte data;

                frmHelp.comPort.Read(buf, 0, n);//读取缓冲数据     
                bool data_1_catched = false;//缓存记录数据是否捕获到    
                buffer.AddRange(buf);
                byte CRCH, CRCL;
                if (buffer.Count > 3)
                {
                    // 0x2B: HX83200的Gamma读写、寄存器读写、OTP读写    设置  返回
                    if (buffer[0] == 0x2B && Setting.TempRecord.cmdLen > 0)
                    {
                        if (buffer.Count >= Setting.TempRecord.cmdLen)
                        {
                            Rec_tmp = new byte[Setting.TempRecord.cmdLen];
                            byte[] crcTemp = new byte[Setting.TempRecord.cmdLen];
                            buffer.CopyTo(0, crcTemp, 0, Setting.TempRecord.cmdLen);

                            CRCData.CalculateCrc16(crcTemp, out CRCH, out CRCL);
                            if (buffer[Setting.TempRecord.cmdLen - 2] != CRCH && buffer[Setting.TempRecord.cmdLen - 1] != CRCL)     //CRC校验出错
                            {
                                buffer.RemoveRange(0, buffer.Count);
                            }
                            else
                            {
                                buffer.CopyTo(0, Rec_tmp, 0, Setting.TempRecord.cmdLen);//复制一条完整数据到具体的数据缓存   
                                data_1_catched = true;
                                buffer.RemoveRange(0, Setting.TempRecord.cmdLen);//正确分析一条数据，从缓存中移除数据。 
                            }

                        }
                    }
                    else
                    {
                        buffer.RemoveRange(0, buffer.Count);
                    }
                }
                if (data_1_catched)
                {
                    this.Invoke((EventHandler)(delegate
                    {
                        frmHelp.T1.Enabled = false; //停止超时计数
                        if (Rec_tmp[0] == 0x2B) //HX83200
                        {
                            switch (Rec_tmp[1])
                            {
                                case 0x01:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写寄存器\tOK！\r\n";
                                    }
                                    break;
                                case 0x02:
                                    {
                                        if (Setting.TempRecord.HX83200CmdType == 0x01)  //读普通寄存器
                                        {
                                            if (rdt_HX83200_SW.Checked == true)
                                            {
                                                string tmp = "";
                                                tmp = String.Format("{0:X2}", Rec_tmp[4]);
                                                txtHX83200Data.Text = tmp;

                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "读寄存器\tOK！\r\n";
                                            }
                                            else if (rdt_HX83200_LW.Checked == true)  //register read
                                            {
                                                string tmp = "";
                                                for (int i = 3; i < (Setting.TempRecord.cmdLen - 3); i++)
                                                {
                                                    tmp = tmp + String.Format("{0:X2}", Rec_tmp[i]) + ",";
                                                }
                                                tmp = tmp + String.Format("{0:X2}", Rec_tmp[Setting.TempRecord.cmdLen - 3]);
                                                txtHX83200Add.Text = tmp;
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "寄存器\t读 OK！\r\n";
                                            }

                                        }
                                    }
                                    break;

                                case 0x08:
                                    {
                                        if (Rec_tmp[4] == 0x00)
                                        {
                                            if (Rec_tmp[3] == 0x00)
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "红 Gamma数据\t写 OK！\r\n";
                                            else if (Rec_tmp[3] == 0x42)
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "绿 Gamma数据\t写 OK！\r\n";
                                            else if (Rec_tmp[3] == 0x81)
                                                frmHelp.textBox1.Text = frmHelp.textBox1.Text + "蓝 Gamma数据\t写 OK！\r\n";
                                        }
                                    }
                                    break;
                                case 0x0A:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写Gamma OTP\t写 OK！\r\n";
                                        else if (Rec_tmp[3] == 0x02)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写Gamma OTP\t写 ERROR！\r\n";
                                    }
                                    break;
                                case 0x0B:
                                    {
                                        string tmp = "";
                                        tmp = String.Format("{0:X2}", Rec_tmp[4]);
                                        HX83200_OTPtime.Text = tmp;
                                        frmHelp.textBox1.Text = frmHelp.textBox1.Text + "Gamma OTP\t读 OK！\r\n";
                                    }
                                    break;
                                case 0x0C:
                                    {
                                        if (Rec_tmp[3] == 0x00)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写Others OTP\t写 OK！\r\n";
                                        else if (Rec_tmp[3] == 0x02)
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "写Others OTP\t写 ERROR！\r\n";
                                    }
                                    break;
                                case 0x09:
                                    {
                                        if (Setting.TempRecord.HX83200CmdType == 0x03)
                                        {
                                            HX83200_R0.Value = Decimal.Parse((Rec_tmp[60] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[61].ToString());
                                            HX83200_R4.Value = Decimal.Parse((Rec_tmp[58] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[59].ToString());
                                            HX83200_R8.Value = Decimal.Parse((Rec_tmp[56] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[57].ToString());
                                            HX83200_R12.Value = Decimal.Parse((Rec_tmp[54] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[55].ToString());
                                            HX83200_R16.Value = Decimal.Parse((Rec_tmp[52] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                            HX83200_R20.Value = Decimal.Parse((Rec_tmp[50] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());
                                            HX83200_R28.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            HX83200_R36.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            HX83200_R44.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            HX83200_R52.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            HX83200_R68.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            HX83200_R84.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            HX83200_R100.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            HX83200_R116.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());
                                            HX83200_R132.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            HX83200_R148.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            HX83200_R164.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            HX83200_R180.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            HX83200_R188.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            HX83200_R196.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            HX83200_R204.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            HX83200_R212.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());
                                            HX83200_R220.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            HX83200_R228.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            HX83200_R236.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            HX83200_R244.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            HX83200_R248.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            HX83200_R252.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            HX83200_R255.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "红 Gamma数据\t读 OK！\r\n";
                                        }
                                        else if (Setting.TempRecord.HX83200CmdType == 0x04)
                                        {
                                            HX83200_G0.Value = Decimal.Parse((Rec_tmp[60] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[61].ToString());
                                            HX83200_G4.Value = Decimal.Parse((Rec_tmp[58] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[59].ToString());
                                            HX83200_G8.Value = Decimal.Parse((Rec_tmp[56] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[57].ToString());
                                            HX83200_G12.Value = Decimal.Parse((Rec_tmp[54] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[55].ToString());
                                            HX83200_G16.Value = Decimal.Parse((Rec_tmp[52] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                            HX83200_G20.Value = Decimal.Parse((Rec_tmp[50] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());
                                            HX83200_G28.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            HX83200_G36.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            HX83200_G44.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            HX83200_G52.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            HX83200_G68.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            HX83200_G84.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            HX83200_G100.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            HX83200_G116.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());
                                            HX83200_G132.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            HX83200_G148.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            HX83200_G164.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            HX83200_G180.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            HX83200_G188.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            HX83200_G196.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            HX83200_G204.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            HX83200_G212.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());
                                            HX83200_G220.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            HX83200_G228.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            HX83200_G236.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            HX83200_G244.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            HX83200_G248.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            HX83200_G252.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            HX83200_G255.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "绿 Gamma数据\t读 OK！\r\n";
                                        }
                                        else if (Setting.TempRecord.HX83200CmdType == 0x05)
                                        {
                                            HX83200_B0.Value = Decimal.Parse((Rec_tmp[60] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[61].ToString());
                                            HX83200_B4.Value = Decimal.Parse((Rec_tmp[58] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[59].ToString());
                                            HX83200_B8.Value = Decimal.Parse((Rec_tmp[56] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[57].ToString());
                                            HX83200_B12.Value = Decimal.Parse((Rec_tmp[54] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[55].ToString());
                                            HX83200_B16.Value = Decimal.Parse((Rec_tmp[52] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[53].ToString());
                                            HX83200_B20.Value = Decimal.Parse((Rec_tmp[50] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[51].ToString());
                                            HX83200_B28.Value = Decimal.Parse((Rec_tmp[48] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[49].ToString());
                                            HX83200_B36.Value = Decimal.Parse((Rec_tmp[46] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[47].ToString());
                                            HX83200_B44.Value = Decimal.Parse((Rec_tmp[44] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[45].ToString());
                                            HX83200_B52.Value = Decimal.Parse((Rec_tmp[42] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[43].ToString());
                                            HX83200_B68.Value = Decimal.Parse((Rec_tmp[40] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[41].ToString());
                                            HX83200_B84.Value = Decimal.Parse((Rec_tmp[38] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[39].ToString());
                                            HX83200_B100.Value = Decimal.Parse((Rec_tmp[36] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[37].ToString());
                                            HX83200_B116.Value = Decimal.Parse((Rec_tmp[34] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[35].ToString());
                                            HX83200_B132.Value = Decimal.Parse((Rec_tmp[32] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[33].ToString());
                                            HX83200_B148.Value = Decimal.Parse((Rec_tmp[30] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[31].ToString());
                                            HX83200_B164.Value = Decimal.Parse((Rec_tmp[28] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[29].ToString());
                                            HX83200_B180.Value = Decimal.Parse((Rec_tmp[26] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[27].ToString());
                                            HX83200_B188.Value = Decimal.Parse((Rec_tmp[24] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[25].ToString());
                                            HX83200_B196.Value = Decimal.Parse((Rec_tmp[22] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[23].ToString());
                                            HX83200_B204.Value = Decimal.Parse((Rec_tmp[20] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[21].ToString());
                                            HX83200_B212.Value = Decimal.Parse((Rec_tmp[18] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[19].ToString());
                                            HX83200_B220.Value = Decimal.Parse((Rec_tmp[16] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[17].ToString());
                                            HX83200_B228.Value = Decimal.Parse((Rec_tmp[14] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[15].ToString());
                                            HX83200_B236.Value = Decimal.Parse((Rec_tmp[12] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[13].ToString());
                                            HX83200_B244.Value = Decimal.Parse((Rec_tmp[10] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[11].ToString());
                                            HX83200_B248.Value = Decimal.Parse((Rec_tmp[8] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[9].ToString());
                                            HX83200_B252.Value = Decimal.Parse((Rec_tmp[6] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[7].ToString());
                                            HX83200_B255.Value = Decimal.Parse((Rec_tmp[4] & 0x03).ToString()) * 256 + Decimal.Parse(Rec_tmp[5].ToString());
                                            frmHelp.textBox1.Text = frmHelp.textBox1.Text + "蓝 Gamma数据\t读 OK！\r\n";
                                        }
                                    }
                                    break;
                                default: break;

                            }
                        }
                        frmHelp.textBox1.SelectionStart = this.frmHelp.textBox1.Text.Length;
                        frmHelp.textBox1.ScrollToCaret();//滚动到光标处
                        if (frmHelp.textBox1.Lines.Length > 50) frmHelp.textBox1.Text = null;
                    }));
                }
            }
            finally
            {
                Listening = false;
            }
        }
        //Gamma保存
        private void NT37710_SaveGamma_Click(object sender, EventArgs e)
        {
            SaveFileDialog sf = new SaveFileDialog(); //对话框
            sf.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; //定义保存的文件的类型
            string str = "保存Gamma文件";
            if (sf.ShowDialog() == DialogResult.OK) //如果确定保存
            {
                if (sf.FileName == "") return; //如果没有输入文件名
                try
                {
                    StreamWriter sw = null; //文件流
                    sw = new StreamWriter(sf.FileName, false, Encoding.UTF8);
                    str = str + "R0," + HX83200_R0.Text + "," + "G0," + HX83200_G0.Text + "," + "B0," + HX83200_B0.Text + "\r\n";
                    str = str + "R4," + HX83200_R4.Text + "," + "G4," + HX83200_G4.Text + "," + "B4," + HX83200_B4.Text + "\r\n";
                    str = str + "R8," + HX83200_R8.Text + "," + "G8," + HX83200_G8.Text + "," + "B8," + HX83200_B8.Text + "\r\n";
                    str = str + "R12," + HX83200_R12.Text + "," + "G12," + HX83200_G12.Text + "," + "B12," + HX83200_B12.Text + "\r\n";
                    str = str + "R16," + HX83200_R16.Text + "," + "G16," + HX83200_G16.Text + "," + "B16," + HX83200_B16.Text + "\r\n";
                    str = str + "R20," + HX83200_R20.Text + "," + "G20," + HX83200_G20.Text + "," + "B20," + HX83200_B20.Text + "\r\n";
                    str = str + "R28," + HX83200_R28.Text + "," + "G28," + HX83200_G28.Text + "," + "B28," + HX83200_B28.Text + "\r\n";
                    str = str + "R36," + HX83200_R36.Text + "," + "G36," + HX83200_G36.Text + "," + "B36," + HX83200_B36.Text + "\r\n";
                    str = str + "R44," + HX83200_R44.Text + "," + "G44," + HX83200_G44.Text + "," + "B44," + HX83200_B44.Text + "\r\n";
                    str = str + "R52," + HX83200_R52.Text + "," + "G52," + HX83200_G52.Text + "," + "B52," + HX83200_B52.Text + "\r\n";
                    str = str + "R68," + HX83200_R68.Text + "," + "G68," + HX83200_G68.Text + "," + "B68," + HX83200_B68.Text + "\r\n";
                    str = str + "R84," + HX83200_R84.Text + "," + "G84," + HX83200_G84.Text + "," + "B84," + HX83200_B84.Text + "\r\n";
                    str = str + "R100," + HX83200_R100.Text + "," + "G100," + HX83200_G100.Text + "," + "B100," + HX83200_B100.Text + "\r\n";
                    str = str + "R116," + HX83200_R116.Text + "," + "G116," + HX83200_G116.Text + "," + "B116," + HX83200_B116.Text + "\r\n";
                    str = str + "R132," + HX83200_R132.Text + "," + "G132," + HX83200_G132.Text + "," + "B132," + HX83200_B132.Text + "\r\n";
                    str = str + "R148," + HX83200_R148.Text + "," + "G148," + HX83200_G148.Text + "," + "B148," + HX83200_B148.Text + "\r\n";
                    str = str + "R164," + HX83200_R164.Text + "," + "G164," + HX83200_G164.Text + "," + "B164," + HX83200_B164.Text + "\r\n";
                    str = str + "R180," + HX83200_R180.Text + "," + "G180," + HX83200_G180.Text + "," + "B180," + HX83200_B180.Text + "\r\n";
                    str = str + "R188," + HX83200_R188.Text + "," + "G188," + HX83200_G188.Text + "," + "B188," + HX83200_B188.Text + "\r\n";
                    str = str + "R196," + HX83200_R196.Text + "," + "G196," + HX83200_G196.Text + "," + "B196," + HX83200_B196.Text + "\r\n";
                    str = str + "R204," + HX83200_R204.Text + "," + "G204," + HX83200_G204.Text + "," + "B204," + HX83200_B204.Text + "\r\n";
                    str = str + "R212," + HX83200_R212.Text + "," + "G212," + HX83200_G212.Text + "," + "B212," + HX83200_B212.Text + "\r\n";
                    str = str + "R220," + HX83200_R220.Text + "," + "G220," + HX83200_G220.Text + "," + "B220," + HX83200_B220.Text + "\r\n";
                    str = str + "R228," + HX83200_R228.Text + "," + "G228," + HX83200_G228.Text + "," + "B228," + HX83200_B228.Text + "\r\n";
                    str = str + "R236," + HX83200_R236.Text + "," + "G236," + HX83200_G236.Text + "," + "B236," + HX83200_B236.Text + "\r\n";
                    str = str + "R244," + HX83200_R244.Text + "," + "G244," + HX83200_G244.Text + "," + "B244," + HX83200_B244.Text + "\r\n";
                    str = str + "R248," + HX83200_R248.Text + "," + "G248," + HX83200_G248.Text + "," + "B248," + HX83200_B248.Text + "\r\n";
                    str = str + "R252," + HX83200_R252.Text + "," + "G252," + HX83200_G252.Text + "," + "B252," + HX83200_B252.Text + "\r\n";
                    str = str + "R255," + HX83200_R255.Text + "," + "G255," + HX83200_G255.Text + "," + "B255," + HX83200_B255.Text + "\r\n";
                    sw.WriteLine(str);
                    sw.Dispose(); //释放资源
                    sw.Close(); //关闭数据流
                    MessageBox.Show("Gamma保存OK！", "系统提示：");
                }
                catch
                {
                    MessageBox.Show("Gamma保存时发生错误，请再试！", "系统提示：");
                }
            }
        } //
        //Gamma载入
        private void NT37710_LoadGamma_Click(object sender, EventArgs e)
        {
            OpenFileDialog of = new OpenFileDialog();
            string strtmp = "";
            of.Filter = @"csv文件(*.csv)|*.csv|所有文件(*.*)|*.*"; ;
            of.Title = "打开Gamma文件";

            if (of.ShowDialog() == DialogResult.OK)
            {
                //读取文本信息
                FileStream fs = new FileStream(of.FileName, FileMode.Open, FileAccess.Read);
                StreamReader streamReader = new StreamReader(fs, Encoding.GetEncoding("GBK"));
                streamReader.BaseStream.Seek(0, SeekOrigin.Begin);
                string strLine = streamReader.ReadLine();
                //循环读取文本信息
                while (!string.IsNullOrEmpty(strLine))
                {
                    strtmp = strtmp + strLine + ",";
                    strLine = streamReader.ReadLine(); //循环读取下一行
                }
                fs.Close(); //关闭流
                streamReader.Close();
                string[] arrtmp = strtmp.Split(new Char[] { ',' });
                HX83200_R0.Text = arrtmp[1].ToString(); HX83200_G0.Text = arrtmp[3].ToString(); HX83200_B0.Text = arrtmp[5].ToString();
                HX83200_R4.Text = arrtmp[7].ToString(); HX83200_G4.Text = arrtmp[9].ToString(); HX83200_B4.Text = arrtmp[11].ToString();
                HX83200_R8.Text = arrtmp[13].ToString(); HX83200_G8.Text = arrtmp[15].ToString(); HX83200_B8.Text = arrtmp[17].ToString();
                HX83200_R12.Text = arrtmp[19].ToString(); HX83200_G12.Text = arrtmp[21].ToString(); HX83200_B12.Text = arrtmp[23].ToString();
                HX83200_R16.Text = arrtmp[25].ToString(); HX83200_G16.Text = arrtmp[27].ToString(); HX83200_B16.Text = arrtmp[29].ToString();
                HX83200_R20.Text = arrtmp[31].ToString(); HX83200_G20.Text = arrtmp[33].ToString(); HX83200_B20.Text = arrtmp[35].ToString();
                HX83200_R28.Text = arrtmp[37].ToString(); HX83200_G28.Text = arrtmp[39].ToString(); HX83200_B28.Text = arrtmp[41].ToString();
                HX83200_R36.Text = arrtmp[43].ToString(); HX83200_G36.Text = arrtmp[45].ToString(); HX83200_B36.Text = arrtmp[47].ToString();
                HX83200_R44.Text = arrtmp[49].ToString(); HX83200_G44.Text = arrtmp[51].ToString(); HX83200_B44.Text = arrtmp[53].ToString();
                HX83200_R52.Text = arrtmp[55].ToString(); HX83200_G52.Text = arrtmp[57].ToString(); HX83200_B52.Text = arrtmp[59].ToString();
                HX83200_R68.Text = arrtmp[61].ToString(); HX83200_G68.Text = arrtmp[63].ToString(); HX83200_B68.Text = arrtmp[65].ToString();
                HX83200_R84.Text = arrtmp[67].ToString(); HX83200_G84.Text = arrtmp[69].ToString(); HX83200_B84.Text = arrtmp[71].ToString();
                HX83200_R100.Text = arrtmp[73].ToString(); HX83200_G100.Text = arrtmp[75].ToString(); HX83200_B100.Text = arrtmp[77].ToString();
                HX83200_R116.Text = arrtmp[79].ToString(); HX83200_G116.Text = arrtmp[81].ToString(); HX83200_B116.Text = arrtmp[83].ToString();
                HX83200_R132.Text = arrtmp[85].ToString(); HX83200_G132.Text = arrtmp[87].ToString(); HX83200_B132.Text = arrtmp[89].ToString();
                HX83200_R148.Text = arrtmp[91].ToString(); HX83200_G148.Text = arrtmp[93].ToString(); HX83200_B148.Text = arrtmp[95].ToString();
                HX83200_R164.Text = arrtmp[97].ToString(); HX83200_G164.Text = arrtmp[99].ToString(); HX83200_B164.Text = arrtmp[101].ToString();
                HX83200_R180.Text = arrtmp[103].ToString(); HX83200_G180.Text = arrtmp[105].ToString(); HX83200_B180.Text = arrtmp[107].ToString();
                HX83200_R188.Text = arrtmp[109].ToString(); HX83200_G188.Text = arrtmp[111].ToString(); HX83200_B188.Text = arrtmp[113].ToString();
                HX83200_R196.Text = arrtmp[115].ToString(); HX83200_G196.Text = arrtmp[117].ToString(); HX83200_B196.Text = arrtmp[119].ToString();
                HX83200_R204.Text = arrtmp[121].ToString(); HX83200_G204.Text = arrtmp[123].ToString(); HX83200_B204.Text = arrtmp[125].ToString();
                HX83200_R212.Text = arrtmp[127].ToString(); HX83200_G212.Text = arrtmp[129].ToString(); HX83200_B212.Text = arrtmp[131].ToString();
                HX83200_R220.Text = arrtmp[133].ToString(); HX83200_G220.Text = arrtmp[135].ToString(); HX83200_B220.Text = arrtmp[137].ToString();
                HX83200_R228.Text = arrtmp[139].ToString(); HX83200_G228.Text = arrtmp[141].ToString(); HX83200_B228.Text = arrtmp[143].ToString();
                HX83200_R236.Text = arrtmp[145].ToString(); HX83200_G236.Text = arrtmp[147].ToString(); HX83200_B236.Text = arrtmp[149].ToString();
                HX83200_R244.Text = arrtmp[151].ToString(); HX83200_G244.Text = arrtmp[153].ToString(); HX83200_B244.Text = arrtmp[155].ToString();
                HX83200_R248.Text = arrtmp[157].ToString(); HX83200_G248.Text = arrtmp[159].ToString(); HX83200_B248.Text = arrtmp[161].ToString();
                HX83200_R252.Text = arrtmp[163].ToString(); HX83200_G252.Text = arrtmp[165].ToString(); HX83200_B252.Text = arrtmp[167].ToString();
                HX83200_R255.Text = arrtmp[169].ToString(); HX83200_G255.Text = arrtmp[171].ToString(); HX83200_B255.Text = arrtmp[173].ToString();
            }
        }

        private void HX83200_trackBar_Scroll(object sender, EventArgs e)
        {
            HX83200_label.Text = HX83200_trackBar.Value.ToString() + "阶";
            txtHX83200Add.Text = "51";
            txtHX83200Data.Text = HX83200_trackBar.Value.ToString("x2");
            HX83200_RegWR_Click(HX83200_RegW, e);
        }
        private void HX83200_GAMMA_Click(object sender, EventArgs e)
        {
            Button btnTmp = (Button)sender;
            Send_buf = new byte[64];
            Setting.TempRecord.cmdLen = 64;
            Send_buf[0] = 0x2B; //NT37710
            Send_buf[2] = 59;  //29绑点*2+1cmd=59

            switch (btnTmp.Name)
            {
                case "HX83200_GammaR_Red":
                    {
                        Setting.TempRecord.HX83200CmdType = 0x03;
                        Send_buf[1] = 0x09;
                        Send_buf[3] = 0x00;
                    }
                    break;
                case "HX83200_GammaR_Green":
                    {
                        Setting.TempRecord.HX83200CmdType = 0x04;
                        Send_buf[1] = 0x09;
                        Send_buf[3] = 0x42;
                    }
                    break;
                case "HX83200_GammaR_Blue":
                    {
                        Setting.TempRecord.HX83200CmdType = 0x05;
                        Send_buf[1] = 0x09;
                        Send_buf[3] = 0x81;
                    }
                    break;
                case "HX83200_GammaW_Red":
                    {
                        Send_buf[1] = 0x08;//写标志
                        Send_buf[3] = 0x00;
                        Send_buf[61] = Convert.ToByte(Convert.ToUInt16(HX83200_R0.Value.ToString()) >> 8);
                        Send_buf[60] = Convert.ToByte((Convert.ToUInt16(HX83200_R0.Value.ToString())) & 0xff);
                        Send_buf[59] = Convert.ToByte(Convert.ToUInt16(HX83200_R4.Value.ToString()) >> 8);
                        Send_buf[58] = Convert.ToByte((Convert.ToUInt16(HX83200_R4.Value.ToString())) & 0xff);
                        Send_buf[57] = Convert.ToByte(Convert.ToUInt16(HX83200_R8.Value.ToString()) >> 8);
                        Send_buf[56] = Convert.ToByte((Convert.ToUInt16(HX83200_R8.Value.ToString())) & 0xff);
                        Send_buf[55] = Convert.ToByte(Convert.ToUInt16(HX83200_R12.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(HX83200_R12.Value.ToString())) & 0xff);
                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(HX83200_R16.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(HX83200_R16.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(HX83200_R20.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(HX83200_R20.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(HX83200_R28.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(HX83200_R28.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(HX83200_R36.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(HX83200_R36.Value.ToString())) & 0xff);

                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(HX83200_R44.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(HX83200_R44.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(HX83200_R52.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(HX83200_R52.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(HX83200_R68.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(HX83200_R68.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(HX83200_R84.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(HX83200_R84.Value.ToString())) & 0xff);
                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(HX83200_R100.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(HX83200_R100.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(HX83200_R116.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(HX83200_R116.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(HX83200_R132.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(HX83200_R132.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(HX83200_R148.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(HX83200_R148.Value.ToString())) & 0xff);

                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(HX83200_R164.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(HX83200_R164.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(HX83200_R180.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(HX83200_R180.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(HX83200_R188.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(HX83200_R188.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(HX83200_R196.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(HX83200_R196.Value.ToString())) & 0xff);
                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(HX83200_R204.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(HX83200_R204.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(HX83200_R212.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(HX83200_R212.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(HX83200_R220.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(HX83200_R220.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(HX83200_R228.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(HX83200_R228.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(HX83200_R236.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(HX83200_R236.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(HX83200_R244.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(HX83200_R244.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(HX83200_R248.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(HX83200_R248.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(HX83200_R252.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(HX83200_R252.Value.ToString())) & 0xff);
                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(HX83200_R255.Value.ToString()) >> 8); //高八位
                        Send_buf[4] = Convert.ToByte((Convert.ToUInt16(HX83200_R255.Value.ToString())) & 0xff); //低八位
                    }
                    break;
                case "HX83200_GammaW_Green":
                    {
                        Send_buf[1] = 0x08;//写标志
                        Send_buf[3] = 0x42;
                        Send_buf[61] = Convert.ToByte(Convert.ToUInt16(HX83200_G0.Value.ToString()) >> 8);
                        Send_buf[60] = Convert.ToByte((Convert.ToUInt16(HX83200_G0.Value.ToString())) & 0xff);
                        Send_buf[59] = Convert.ToByte(Convert.ToUInt16(HX83200_G4.Value.ToString()) >> 8);
                        Send_buf[58] = Convert.ToByte((Convert.ToUInt16(HX83200_G4.Value.ToString())) & 0xff);
                        Send_buf[57] = Convert.ToByte(Convert.ToUInt16(HX83200_G8.Value.ToString()) >> 8);
                        Send_buf[56] = Convert.ToByte((Convert.ToUInt16(HX83200_G8.Value.ToString())) & 0xff);
                        Send_buf[55] = Convert.ToByte(Convert.ToUInt16(HX83200_G12.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(HX83200_G12.Value.ToString())) & 0xff);
                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(HX83200_G16.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(HX83200_G16.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(HX83200_G20.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(HX83200_G20.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(HX83200_G28.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(HX83200_G28.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(HX83200_G36.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(HX83200_G36.Value.ToString())) & 0xff);

                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(HX83200_G44.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(HX83200_G44.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(HX83200_G52.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(HX83200_G52.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(HX83200_G68.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(HX83200_G68.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(HX83200_G84.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(HX83200_G84.Value.ToString())) & 0xff);
                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(HX83200_G100.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(HX83200_G100.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(HX83200_G116.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(HX83200_G116.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(HX83200_G132.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(HX83200_G132.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(HX83200_G148.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(HX83200_G148.Value.ToString())) & 0xff);

                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(HX83200_G164.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(HX83200_G164.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(HX83200_G180.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(HX83200_G180.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(HX83200_G188.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(HX83200_G188.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(HX83200_G196.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(HX83200_G196.Value.ToString())) & 0xff);
                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(HX83200_G204.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(HX83200_G204.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(HX83200_G212.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(HX83200_G212.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(HX83200_G220.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(HX83200_G220.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(HX83200_G228.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(HX83200_G228.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(HX83200_G236.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(HX83200_G236.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(HX83200_G244.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(HX83200_G244.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(HX83200_G248.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(HX83200_G248.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(HX83200_G252.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(HX83200_G252.Value.ToString())) & 0xff);
                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(HX83200_G255.Value.ToString()) >> 8);
                        Send_buf[4] = Convert.ToByte((Convert.ToUInt16(HX83200_G255.Value.ToString())) & 0xff);
                    }
                    break;
                case "HX83200_GammaW_Blue":
                    {
                        Send_buf[1] = 0x08;//写标志
                        Send_buf[3] = 0x81;
                        Send_buf[61] = Convert.ToByte(Convert.ToUInt16(HX83200_B0.Value.ToString()) >> 8);
                        Send_buf[60] = Convert.ToByte((Convert.ToUInt16(HX83200_B0.Value.ToString())) & 0xff);
                        Send_buf[59] = Convert.ToByte(Convert.ToUInt16(HX83200_B4.Value.ToString()) >> 8);
                        Send_buf[58] = Convert.ToByte((Convert.ToUInt16(HX83200_B4.Value.ToString())) & 0xff);
                        Send_buf[57] = Convert.ToByte(Convert.ToUInt16(HX83200_B8.Value.ToString()) >> 8);
                        Send_buf[56] = Convert.ToByte((Convert.ToUInt16(HX83200_B8.Value.ToString())) & 0xff);
                        Send_buf[55] = Convert.ToByte(Convert.ToUInt16(HX83200_B12.Value.ToString()) >> 8);
                        Send_buf[54] = Convert.ToByte((Convert.ToUInt16(HX83200_B12.Value.ToString())) & 0xff);
                        Send_buf[53] = Convert.ToByte(Convert.ToUInt16(HX83200_B16.Value.ToString()) >> 8);
                        Send_buf[52] = Convert.ToByte((Convert.ToUInt16(HX83200_B16.Value.ToString())) & 0xff);
                        Send_buf[51] = Convert.ToByte(Convert.ToUInt16(HX83200_B20.Value.ToString()) >> 8);
                        Send_buf[50] = Convert.ToByte((Convert.ToUInt16(HX83200_B20.Value.ToString())) & 0xff);
                        Send_buf[49] = Convert.ToByte(Convert.ToUInt16(HX83200_B28.Value.ToString()) >> 8);
                        Send_buf[48] = Convert.ToByte((Convert.ToUInt16(HX83200_B28.Value.ToString())) & 0xff);
                        Send_buf[47] = Convert.ToByte(Convert.ToUInt16(HX83200_B36.Value.ToString()) >> 8);
                        Send_buf[46] = Convert.ToByte((Convert.ToUInt16(HX83200_B36.Value.ToString())) & 0xff);

                        Send_buf[45] = Convert.ToByte(Convert.ToUInt16(HX83200_B44.Value.ToString()) >> 8);
                        Send_buf[44] = Convert.ToByte((Convert.ToUInt16(HX83200_B44.Value.ToString())) & 0xff);
                        Send_buf[43] = Convert.ToByte(Convert.ToUInt16(HX83200_B52.Value.ToString()) >> 8);
                        Send_buf[42] = Convert.ToByte((Convert.ToUInt16(HX83200_B52.Value.ToString())) & 0xff);
                        Send_buf[41] = Convert.ToByte(Convert.ToUInt16(HX83200_B68.Value.ToString()) >> 8);
                        Send_buf[40] = Convert.ToByte((Convert.ToUInt16(HX83200_B68.Value.ToString())) & 0xff);
                        Send_buf[39] = Convert.ToByte(Convert.ToUInt16(HX83200_B84.Value.ToString()) >> 8);
                        Send_buf[38] = Convert.ToByte((Convert.ToUInt16(HX83200_B84.Value.ToString())) & 0xff);
                        Send_buf[37] = Convert.ToByte(Convert.ToUInt16(HX83200_B100.Value.ToString()) >> 8);
                        Send_buf[36] = Convert.ToByte((Convert.ToUInt16(HX83200_B100.Value.ToString())) & 0xff);
                        Send_buf[35] = Convert.ToByte(Convert.ToUInt16(HX83200_B116.Value.ToString()) >> 8);
                        Send_buf[34] = Convert.ToByte((Convert.ToUInt16(HX83200_B116.Value.ToString())) & 0xff);
                        Send_buf[33] = Convert.ToByte(Convert.ToUInt16(HX83200_B132.Value.ToString()) >> 8);
                        Send_buf[32] = Convert.ToByte((Convert.ToUInt16(HX83200_B132.Value.ToString())) & 0xff);
                        Send_buf[31] = Convert.ToByte(Convert.ToUInt16(HX83200_B148.Value.ToString()) >> 8);
                        Send_buf[30] = Convert.ToByte((Convert.ToUInt16(HX83200_B148.Value.ToString())) & 0xff);

                        Send_buf[29] = Convert.ToByte(Convert.ToUInt16(HX83200_B164.Value.ToString()) >> 8);
                        Send_buf[28] = Convert.ToByte((Convert.ToUInt16(HX83200_B164.Value.ToString())) & 0xff);
                        Send_buf[27] = Convert.ToByte(Convert.ToUInt16(HX83200_B180.Value.ToString()) >> 8);
                        Send_buf[26] = Convert.ToByte((Convert.ToUInt16(HX83200_B180.Value.ToString())) & 0xff);
                        Send_buf[25] = Convert.ToByte(Convert.ToUInt16(HX83200_B188.Value.ToString()) >> 8);
                        Send_buf[24] = Convert.ToByte((Convert.ToUInt16(HX83200_B188.Value.ToString())) & 0xff);
                        Send_buf[23] = Convert.ToByte(Convert.ToUInt16(HX83200_B196.Value.ToString()) >> 8);
                        Send_buf[22] = Convert.ToByte((Convert.ToUInt16(HX83200_B196.Value.ToString())) & 0xff);
                        Send_buf[21] = Convert.ToByte(Convert.ToUInt16(HX83200_B204.Value.ToString()) >> 8);
                        Send_buf[20] = Convert.ToByte((Convert.ToUInt16(HX83200_B204.Value.ToString())) & 0xff);
                        Send_buf[19] = Convert.ToByte(Convert.ToUInt16(HX83200_B212.Value.ToString()) >> 8);
                        Send_buf[18] = Convert.ToByte((Convert.ToUInt16(HX83200_B212.Value.ToString())) & 0xff);
                        Send_buf[17] = Convert.ToByte(Convert.ToUInt16(HX83200_B220.Value.ToString()) >> 8);
                        Send_buf[16] = Convert.ToByte((Convert.ToUInt16(HX83200_B220.Value.ToString())) & 0xff);
                        Send_buf[15] = Convert.ToByte(Convert.ToUInt16(HX83200_B228.Value.ToString()) >> 8);
                        Send_buf[14] = Convert.ToByte((Convert.ToUInt16(HX83200_B228.Value.ToString())) & 0xff);
                        Send_buf[13] = Convert.ToByte(Convert.ToUInt16(HX83200_B236.Value.ToString()) >> 8);
                        Send_buf[12] = Convert.ToByte((Convert.ToUInt16(HX83200_B236.Value.ToString())) & 0xff);
                        Send_buf[11] = Convert.ToByte(Convert.ToUInt16(HX83200_B244.Value.ToString()) >> 8);
                        Send_buf[10] = Convert.ToByte((Convert.ToUInt16(HX83200_B244.Value.ToString())) & 0xff);
                        Send_buf[9] = Convert.ToByte(Convert.ToUInt16(HX83200_B248.Value.ToString()) >> 8);
                        Send_buf[8] = Convert.ToByte((Convert.ToUInt16(HX83200_B248.Value.ToString())) & 0xff);
                        Send_buf[7] = Convert.ToByte(Convert.ToUInt16(HX83200_B252.Value.ToString()) >> 8);
                        Send_buf[6] = Convert.ToByte((Convert.ToUInt16(HX83200_B252.Value.ToString())) & 0xff);
                        Send_buf[5] = Convert.ToByte(Convert.ToUInt16(HX83200_B255.Value.ToString()) >> 8);
                        Send_buf[4] = Convert.ToByte((Convert.ToUInt16(HX83200_B255.Value.ToString())) & 0xff);
                    }
                    break;
                default: break;
            }
            CRCData.CalculateCrc16(Send_buf, out Send_buf[62], out Send_buf[63]);
            try
            {
                frmHelp.comPort.Write(Send_buf, 0, 64);   //NT37710
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            frmHelp.T1.Enabled = false;
            frmHelp.T1.Interval = 2000;
            frmHelp.T1.Enabled = true;
        }
        private void HX83200_Others_Click(object sender, EventArgs e)
        {
            Send_buf = new byte[7];
            Button btnTmp = (Button)sender;
            Setting.TempRecord.cmdLen = 7;

            Send_buf[0] = 0x2B;
            Send_buf[2] = 0x02;
            switch (btnTmp.Name)
            {
                case "HX83200_OTP":         //otp
                    {
                        Send_buf[1] = 0x0A;
                        {       //保存待otp的gamma
                            FileStream fs = new FileStream("../OTP_gamma_HX83200.txt", FileMode.OpenOrCreate, FileAccess.Write);
                            fs.Close();
                            StreamWriter sw = new StreamWriter(fs.Name, false, Encoding.UTF8);
                            string str = null;
                            str = str + HX83200_R0.Text + "," + HX83200_G0.Text + "," + HX83200_B0.Text + "\r\n";
                            str = str + HX83200_R4.Text + "," + HX83200_G4.Text + "," + HX83200_B4.Text + "\r\n";
                            str = str + HX83200_R8.Text + "," + HX83200_G8.Text + "," + HX83200_B8.Text + "\r\n";
                            str = str + HX83200_R12.Text + "," + HX83200_G12.Text + "," + HX83200_B12.Text + "\r\n";
                            str = str + HX83200_R16.Text + "," + HX83200_G16.Text + "," + HX83200_B16.Text + "\r\n";
                            str = str + HX83200_R20.Text + "," + HX83200_G20.Text + "," + HX83200_B20.Text + "\r\n";
                            str = str + HX83200_R28.Text + "," + HX83200_G28.Text + "," + HX83200_B28.Text + "\r\n";
                            str = str + HX83200_R36.Text + "," + HX83200_G36.Text + "," + HX83200_B36.Text + "\r\n";
                            str = str + HX83200_R44.Text + "," + HX83200_G44.Text + "," + HX83200_B44.Text + "\r\n";
                            str = str + HX83200_R52.Text + "," + HX83200_G52.Text + "," + HX83200_B52.Text + "\r\n";
                            str = str + HX83200_R68.Text + "," + HX83200_G68.Text + "," + HX83200_B68.Text + "\r\n";
                            str = str + HX83200_R84.Text + "," + HX83200_G84.Text + "," + HX83200_B84.Text + "\r\n";
                            str = str + HX83200_R100.Text + "," + HX83200_G100.Text + "," + HX83200_B100.Text + "\r\n";
                            str = str + HX83200_R116.Text + "," + HX83200_G116.Text + "," + HX83200_B116.Text + "\r\n";
                            str = str + HX83200_R132.Text + "," + HX83200_G132.Text + "," + HX83200_B132.Text + "\r\n";
                            str = str + HX83200_R148.Text + "," + HX83200_G148.Text + "," + HX83200_B148.Text + "\r\n";
                            str = str + HX83200_R164.Text + "," + HX83200_G164.Text + "," + HX83200_B164.Text + "\r\n";
                            str = str + HX83200_R180.Text + "," + HX83200_G180.Text + "," + HX83200_B180.Text + "\r\n";
                            str = str + HX83200_R188.Text + "," + HX83200_G188.Text + "," + HX83200_B188.Text + "\r\n";
                            str = str + HX83200_R196.Text + "," + HX83200_G196.Text + "," + HX83200_B196.Text + "\r\n";
                            str = str + HX83200_R204.Text + "," + HX83200_G204.Text + "," + HX83200_B204.Text + "\r\n";
                            str = str + HX83200_R212.Text + "," + HX83200_G212.Text + "," + HX83200_B212.Text + "\r\n";
                            str = str + HX83200_R220.Text + "," + HX83200_G220.Text + "," + HX83200_B255.Text + "\r\n";
                            str = str + HX83200_R228.Text + "," + HX83200_G228.Text + "," + HX83200_B228.Text + "\r\n";
                            str = str + HX83200_R236.Text + "," + HX83200_G236.Text + "," + HX83200_B236.Text + "\r\n";
                            str = str + HX83200_R244.Text + "," + HX83200_G244.Text + "," + HX83200_B244.Text + "\r\n";
                            str = str + HX83200_R248.Text + "," + HX83200_G248.Text + "," + HX83200_B248.Text + "\r\n";
                            str = str + HX83200_R252.Text + "," + HX83200_G252.Text + "," + HX83200_B252.Text + "\r\n";
                            str = str + HX83200_R255.Text + "," + HX83200_G255.Text + "," + HX83200_B255.Text + "\r\n";
                            sw.WriteLine(str);
                            sw.Dispose(); //释放资源
                            sw.Close(); //关闭数据流
                        }
                    }
                    break;
                case "HX83200_OTP_Pages":
                    {
                        byte HX83200_Page_Choise = 0;
                        Send_buf[1] = 0x0C;
                        if (HX83200_gp0.Checked == true)
                            HX83200_Page_Choise |= 0x01;
                        if (HX83200_gp1.Checked == true)
                            HX83200_Page_Choise |= 0x02;
                        if (HX83200_gp2.Checked == true)
                            HX83200_Page_Choise |= 0x04;
                        if (HX83200_gp3.Checked == true)
                            HX83200_Page_Choise |= 0x08;
                        if (HX83200_gp4.Checked == true)
                            HX83200_Page_Choise |= 0x10;
                        if (HX83200_gp6.Checked == true)
                            HX83200_Page_Choise |= 0x20;
                        if (HX83200_gp14.Checked == true)
                            HX83200_Page_Choise |= 0x40;
                        if (HX83200_gp15.Checked == true)
                            HX83200_Page_Choise |= 0x80;
                        Send_buf[3] = HX83200_Page_Choise;
                    }
                    break;
                case "HX83200_OTP_Page_time_Read":
                    {
                        Setting.TempRecord.NT37710CmdType = 0x01;   //读普通寄存器
                        Send_buf[1] = 0x0D;
                        byte HX83200_Page_Choise_read = 0;
                        if (HX83200_gp0.Checked == true)
                            HX83200_Page_Choise_read |= 0x01;
                        if (HX83200_gp1.Checked == true)
                            HX83200_Page_Choise_read |= 0x02;
                        if (HX83200_gp2.Checked == true)
                            HX83200_Page_Choise_read |= 0x04;
                        if (HX83200_gp3.Checked == true)
                            HX83200_Page_Choise_read |= 0x08;
                        if (HX83200_gp4.Checked == true)
                            HX83200_Page_Choise_read |= 0x10;
                        if (HX83200_gp6.Checked == true)
                            HX83200_Page_Choise_read |= 0x20;
                        if (HX83200_gp14.Checked == true)
                            HX83200_Page_Choise_read |= 0x40;
                        if (HX83200_gp15.Checked == true)
                            HX83200_Page_Choise_read |= 0x80;
                        Send_buf[3] = HX83200_Page_Choise_read;
                    }
                    break;
                case "HX83200_OTP_time_Read":         //Read
                    {
                        Setting.TempRecord.NT37710CmdType = 0x01;   //读普通寄存器
                        Send_buf[1] = 0x0B;
                    }
                    break;
                default:
                    break;
            }
            CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
            try
            {
                frmHelp.comPort.Write(Send_buf, 0, 7);
            }
            catch
            {
                MessageBox.Show("串口有误，请检查", "错误");
            }
            frmHelp.T1.Enabled = false;
            frmHelp.T1.Interval = 2000;
            frmHelp.T1.Enabled = true;
        }
        private void rdt_HX83200_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton radbtnTmp = (RadioButton)sender;
            switch (radbtnTmp.Name)
            {
                case "rdt_HX83200_SW":
                    {
                        label0_HX83200.Text = "data";
                        txtHX83200Add.MaxLength = 2;
                    }
                    break;
                case "rdt_HX83200_LW":
                    {
                        label0_HX83200.Text = "个数";
                        txtHX83200Add.MaxLength = 1000;
                    }
                    break;
                default:
                    break;
            }
        }
        private void HX83200_RegWR_Click(object sender, EventArgs e)
        {
            Send_buf = new byte[7];
            Button btnTmp = (Button)sender;
            Setting.TempRecord.cmdLen = 7;
            Int32 DataNum = 0;
            Send_buf[0] = 0x2B; //NH83200A
            Send_buf[2] = 0x02;

            switch (btnTmp.Name)
            {
                case "HX83200_RegR":
                    {
                        Setting.TempRecord.HX83200CmdType = 0x01;   //读普通寄存器                   
                        if (rdt_HX83200_SW.Checked == true)
                        {
                            Send_buf[1] = 0x02;
                            Send_buf[3] = byte.Parse((Convert.ToInt32(txtHX83200Add.Text.Trim(), 16)).ToString());
                            CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
                            try
                            {
                                frmHelp.comPort.Write(Send_buf, 0, 7);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                            }
                        }
                        else if (rdt_HX83200_LW.Checked == true)
                        {
                            string strLine = Convert.ToString(txtHX83200Add.Text);  //data
                            string[] arr = strLine.Split(','); //以逗号分割，添加到数组
                            try
                            {
                                DataNum = Convert.ToInt32(txtHX83200Data.Text) + 1;
                                Setting.TempRecord.cmdLen = DataNum + 5;
                                Send_buf = new byte[DataNum + 5];
                                Send_buf[0] = 0x2B;
                                Send_buf[1] = 0x02;
                                Send_buf[2] = byte.Parse(Convert.ToString(DataNum));
                                Send_buf[3] = byte.Parse((Convert.ToInt32(arr[0], 16)).ToString());
                                CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + DataNum - 2], out Send_buf[5 + DataNum - 1]);
                            }
                            catch
                            {
                                MessageBox.Show("读取长度有误，请检查", "错误");
                                break;
                            }
                            try
                            {
                                frmHelp.comPort.Write(Send_buf, 0, 5 + DataNum);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                            }
                        }
                    }
                    break;
                case "HX83200_RegW":         //w写寄存器
                    {
                        Send_buf[1] = 0x01;  //写操作-短包
                        if (rdt_HX83200_SW.Checked == true)
                        {
                            label0_HX83200.Text = "data";
                            Send_buf[3] = byte.Parse((Convert.ToInt32(txtHX83200Add.Text.Trim(), 16)).ToString());
                            Send_buf[4] = byte.Parse((Convert.ToInt32(txtHX83200Data.Text.Trim(), 16)).ToString());

                            CRCData.CalculateCrc16(Send_buf, out Send_buf[5], out Send_buf[6]);
                            try
                            {
                                frmHelp.comPort.Write(Send_buf, 0, 7);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                            }
                        }
                        else if (rdt_HX83200_LW.Checked == true)   //写操作-长包
                        {
                            label0_HX83200.Text = "回读个数";
                            string strLine = Convert.ToString(txtHX83200Add.Text);
                            string[] arr = strLine.Split(','); //以逗号分割，添加到数组

                            Setting.TempRecord.cmdLen = arr.Length + 5;
                            Send_buf = new byte[arr.Length + 5];
                            Send_buf[0] = 0x2B;
                            Send_buf[1] = 0x01;
                            Send_buf[2] = byte.Parse(arr.Length.ToString());
                            for (int i = 0; i < arr.Length; i++)
                            {
                                Send_buf[3 + i] = byte.Parse((Convert.ToInt32(arr[i], 16)).ToString());
                            }
                            CRCData.CalculateCrc16(Send_buf, out Send_buf[5 + arr.Length - 2], out Send_buf[5 + arr.Length - 1]);
                            try
                            {
                                frmHelp.comPort.Write(Send_buf, 0, 5 + arr.Length);
                            }
                            catch
                            {
                                MessageBox.Show("串口有误，请检查", "错误");
                            }
                        }
                    }
                    break;
                default:
                    break;
            }

            frmHelp.T1.Enabled = false;
            frmHelp.T1.Interval = 2000;
            frmHelp.T1.Enabled = true;
        }

        //HX83200
        private int[] Parttern_HX83200 = new int[28] { 255, 252, 248, 244, 236, 228, 220, 212, 204, 196, 188, 180, 164, 148, 132, 116, 100, 84, 68, 52, 44, 36, 28, 20, 16, 12, 8, 4 };
        private void btnHXStop_Click(object sender, EventArgs e)
        {
            frmHelp.T20.Enabled = false;
            flag1 = 1;
            flag2 = 1;
            flag3 = 1;
            adjust_Rnum = 0;
            adjust_Gnum = 0;
            adjust_Bnum = 0;
            adjust_l = 0;
            adjust_x = 0;
            adjust_y = 0;
        }
        private void btnCalculateHX_Click(object sender, EventArgs e)
        {
            texthx_255.Text = (Math.Pow((Parttern_HX83200[0] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_252.Text = (Math.Pow((Parttern_HX83200[1] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_248.Text = (Math.Pow((Parttern_HX83200[2] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_244.Text = (Math.Pow((Parttern_HX83200[3] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_236.Text = (Math.Pow((Parttern_HX83200[4] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_228.Text = (Math.Pow((Parttern_HX83200[5] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_220.Text = (Math.Pow((Parttern_HX83200[6] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_212.Text = (Math.Pow((Parttern_HX83200[7] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_204.Text = (Math.Pow((Parttern_HX83200[8] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_196.Text = (Math.Pow((Parttern_HX83200[9] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_188.Text = (Math.Pow((Parttern_HX83200[10] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_180.Text = (Math.Pow((Parttern_HX83200[11] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_164.Text = (Math.Pow((Parttern_HX83200[12] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_148.Text = (Math.Pow((Parttern_HX83200[13] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_132.Text = (Math.Pow((Parttern_HX83200[14] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_116.Text = (Math.Pow((Parttern_HX83200[15] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_100.Text = (Math.Pow((Parttern_HX83200[16] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_84.Text = (Math.Pow((Parttern_HX83200[17] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_68.Text = (Math.Pow((Parttern_HX83200[18] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_52.Text = (Math.Pow((Parttern_HX83200[19] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_44.Text = (Math.Pow((Parttern_HX83200[20] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_36.Text = (Math.Pow((Parttern_HX83200[21] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_28.Text = (Math.Pow((Parttern_HX83200[22] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_20.Text = (Math.Pow((Parttern_HX83200[23] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_16.Text = (Math.Pow((Parttern_HX83200[24] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_12.Text = (Math.Pow((Parttern_HX83200[25] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_8.Text = (Math.Pow((Parttern_HX83200[26] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
            texthx_4.Text = (Math.Pow((Parttern_HX83200[27] / 255.0), Convert.ToDouble(txt_HX_gamma.Text)) * Convert.ToDouble(txt_HX_l.Text)).ToString("F4");
        }
        private void btnAutogammaHX_Click(object sender, EventArgs e)
        {
            int flag = 1;
            double Lr_d, Lg_d, Lb_d;
            D_lums = new double[28, 3];
            D_lum = new double[28];
            index = 0;
            adjust_Rnum = 0;
            adjust_Gnum = 0;
            adjust_Bnum = 0;
            adjust_l = 0;
            adjust_x = 0;
            adjust_y = 0;

            D_lum[0] = Convert.ToDouble(texthx_255.Text);
            D_lum[1] = Convert.ToDouble(texthx_252.Text);
            D_lum[2] = Convert.ToDouble(texthx_248.Text);
            D_lum[3] = Convert.ToDouble(texthx_244.Text);
            D_lum[4] = Convert.ToDouble(texthx_236.Text);
            D_lum[5] = Convert.ToDouble(texthx_228.Text);
            D_lum[6] = Convert.ToDouble(texthx_220.Text);
            D_lum[7] = Convert.ToDouble(texthx_212.Text);
            D_lum[8] = Convert.ToDouble(texthx_204.Text);
            D_lum[9] = Convert.ToDouble(texthx_196.Text);
            D_lum[10] = Convert.ToDouble(texthx_188.Text);
            D_lum[11] = Convert.ToDouble(texthx_180.Text);
            D_lum[12] = Convert.ToDouble(texthx_164.Text);
            D_lum[13] = Convert.ToDouble(texthx_148.Text);
            D_lum[14] = Convert.ToDouble(texthx_132.Text);
            D_lum[15] = Convert.ToDouble(texthx_116.Text);
            D_lum[16] = Convert.ToDouble(texthx_100.Text);
            D_lum[17] = Convert.ToDouble(texthx_84.Text);
            D_lum[18] = Convert.ToDouble(texthx_68.Text);
            D_lum[19] = Convert.ToDouble(texthx_52.Text);
            D_lum[20] = Convert.ToDouble(texthx_44.Text);
            D_lum[21] = Convert.ToDouble(texthx_36.Text);
            D_lum[22] = Convert.ToDouble(texthx_28.Text);
            D_lum[23] = Convert.ToDouble(texthx_20.Text);
            D_lum[24] = Convert.ToDouble(texthx_16.Text);
            D_lum[25] = Convert.ToDouble(texthx_12.Text);
            D_lum[26] = Convert.ToDouble(texthx_8.Text);
            D_lum[27] = Convert.ToDouble(texthx_4.Text);
            D_x = Convert.ToDouble(txt_HX_x.Text);
            D_y = Convert.ToDouble(txt_HX_y.Text);
            Lr_d = CaSDKObj.R_y * ((D_y - CaSDKObj.G_y) * (CaSDKObj.B_x - D_x) + (D_x - CaSDKObj.G_x) * (D_y - CaSDKObj.B_y)) / CaSDKObj.B_y / ((D_y - CaSDKObj.G_y) * (D_x - CaSDKObj.R_x) + (D_x - CaSDKObj.G_x) * (CaSDKObj.R_y - D_y));
            Lb_d = 1.0;
            Lg_d = CaSDKObj.G_y * ((D_y - CaSDKObj.R_y) * (CaSDKObj.B_x - D_x) + (D_x - CaSDKObj.R_x) * (D_y - CaSDKObj.B_y)) / CaSDKObj.B_y / ((D_y - CaSDKObj.R_y) * (D_x - CaSDKObj.G_x) + (D_x - CaSDKObj.R_x) * (CaSDKObj.G_y - D_y));

            for (int i = 0; i < 28; i++)
            {
                D_lums[i, 0] = D_lum[i] * Lr_d / (Lr_d + Lg_d + Lb_d);
                D_lums[i, 1] = D_lum[i] * Lg_d / (Lr_d + Lg_d + Lb_d);
                D_lums[i, 2] = D_lum[i] * Lb_d / (Lr_d + Lg_d + Lb_d);
            }

            switch (flag)
            {
                case 1://寄存器值与亮度正比
                    {
                        lum_off = Convert.ToDouble(txt_HX_loff.Text);
                        x_off = Convert.ToDouble(txt_HX_xoff.Text);
                        y_off = Convert.ToDouble(txt_HX_yoff.Text);
                        HX83200_GAMMA_Click(HX83200_GammaW_Red, e);
                        HX83200_GAMMA_Click(HX83200_GammaW_Green, e);
                        HX83200_GAMMA_Click(HX83200_GammaW_Blue, e);
                        Application.DoEvents();
                        frmHelp.OLED_Show_Click(frmHelp.btnwhite, e);
                        frmHelp.T20.Enabled = true;
                    }
                    break;
                case 2://寄存器值与亮度反比
                    break;
                default:
                    break;
            }
        }
        private void HX83200_auto_gamma(Object sender, EventArgs e)
        {
            double Lr_t, Lg_t, Lb_t, lumr, lumg, lumb;
            frmHelp.Msr_CASDK();

            if ((frmHelp.CASDK_LUM < (D_lum[index] + lum_off)) && (frmHelp.CASDK_LUM > (D_lum[index] - lum_off)))//G
                flag1 = 0;
            if ((frmHelp.CASDK_y < (D_y + y_off)) && (frmHelp.CASDK_y > (D_y - y_off)) && flag1 == 0)//B
                flag2 = 0;
            if ((frmHelp.CASDK_x < (D_x + x_off)) && (frmHelp.CASDK_x > (D_x - x_off)) && flag1 == 0 && flag2 == 0)//R
                flag3 = 0;

            if (flag1 == 0 && flag2 == 0 && flag3 == 0)
            {
                frmHelp.T20.Enabled = false;
                index++;
                adjust_Rnum = 0;
                adjust_Gnum = 0;
                adjust_Bnum = 0;
                adjust_l = 0;
                adjust_x = 0;
                adjust_y = 0;
                if (index == 28)
                {
                    frmHelp.textBox1.Text = frmHelp.textBox1.Text + "RM67195/295/198 gamma调试完毕!\r\n";
                }
                if (index < 28)
                {
                    switch (index)
                    {
                        case 1:
                            lum_off = Convert.ToDouble(texthx_252_off.Text);
                            break;
                        case 2:
                            lum_off = Convert.ToDouble(texthx_248_off.Text);
                            break;
                        case 3:
                            lum_off = Convert.ToDouble(texthx_244_off.Text);
                            break;
                        case 4:
                            lum_off = Convert.ToDouble(texthx_236_off.Text);
                            break;
                        case 5:
                            lum_off = Convert.ToDouble(texthx_228_off.Text);
                            break;
                        case 6:
                            lum_off = Convert.ToDouble(texthx_220_off.Text);
                            break;
                        case 7:
                            lum_off = Convert.ToDouble(texthx_212_off.Text);
                            break;
                        case 8:
                            lum_off = Convert.ToDouble(texthx_204_off.Text);
                            break;
                        case 9:
                            lum_off = Convert.ToDouble(texthx_196_off.Text);
                            break;
                        case 10:
                            lum_off = Convert.ToDouble(texthx_188_off.Text);
                            break;
                        case 11:
                            lum_off = Convert.ToDouble(texthx_180_off.Text);
                            break;
                        case 12:
                            lum_off = Convert.ToDouble(texthx_164_off.Text);
                            break;
                        case 13:
                            lum_off = Convert.ToDouble(texthx_148_off.Text);
                            break;
                        case 14:
                            lum_off = Convert.ToDouble(texthx_132_off.Text) * Convert.ToDouble(texthx_132.Text) / 100;
                            break;
                        case 15:
                            lum_off = Convert.ToDouble(texthx_116_off.Text) * Convert.ToDouble(texthx_116.Text) / 100;
                            break;
                        case 16:
                            lum_off = Convert.ToDouble(texthx_100_off.Text) * Convert.ToDouble(texthx_100.Text) / 100;
                            break;
                        case 17:
                            lum_off = Convert.ToDouble(texthx_84_off.Text) * Convert.ToDouble(texthx_84.Text) / 100;
                            break;
                        case 18:
                            lum_off = Convert.ToDouble(texthx_68_off.Text) * Convert.ToDouble(texthx_68.Text) / 100;
                            break;
                        case 19:
                            lum_off = Convert.ToDouble(texthx_52_off.Text) * Convert.ToDouble(texthx_52.Text) / 100;
                            break;
                        case 20:
                            lum_off = Convert.ToDouble(texthx_44_off.Text) * Convert.ToDouble(texthx_44.Text) / 100;
                            break;
                        case 21:
                            lum_off = Convert.ToDouble(texthx_36_off.Text) * Convert.ToDouble(texthx_36.Text) / 100;
                            break;
                        case 22:
                            lum_off = Convert.ToDouble(texthx_28_off.Text) * Convert.ToDouble(texthx_28.Text) / 100;
                            break;
                        case 23:
                            lum_off = Convert.ToDouble(texthx_20_off.Text) * Convert.ToDouble(texthx_20.Text) / 100;
                            break;
                        case 24:
                            {
                                lum_off = Convert.ToDouble(texthx_16_off.Text) * Convert.ToDouble(texthx_16.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                            }
                            break;
                        case 25:
                            {
                                lum_off = Convert.ToDouble(texthx_12_off.Text) * Convert.ToDouble(texthx_12.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                            }
                            break;
                        case 26:
                            {
                                lum_off = Convert.ToDouble(texthx_8_off.Text) * Convert.ToDouble(texthx_8.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                            }
                            break;
                        case 27:
                            {
                                lum_off = Convert.ToDouble(texthx_4_off.Text) * Convert.ToDouble(texthx_4.Text) / 100;
                                x_off = x_off + 0.001;
                                y_off = y_off + 0.001;
                            }
                            break;
                    }
                    frmHelp.numPatternR.Value = Parttern_HX83200[index];
                    frmHelp.numPatternG.Value = Parttern_HX83200[index];
                    frmHelp.numPatternB.Value = Parttern_HX83200[index];
                    Application.DoEvents();
                    frmHelp.OLED_Show_Click(frmHelp.btnPatternW, e);//写入Pattern参数
                    Thread.Sleep(10); //1秒=1000毫秒，
                    frmHelp.T20.Enabled = true;
                    flag1 = 1;
                    flag2 = 1;
                    flag3 = 1;
                }
            }
            else
            {
                Lr_t = CaSDKObj.R_y * ((frmHelp.CASDK_y - CaSDKObj.G_y) * (CaSDKObj.B_x - frmHelp.CASDK_x) + (frmHelp.CASDK_x - CaSDKObj.G_x) * (frmHelp.CASDK_y - CaSDKObj.B_y)) / CaSDKObj.B_y / ((frmHelp.CASDK_y - CaSDKObj.G_y) * (frmHelp.CASDK_x - CaSDKObj.R_x) + (frmHelp.CASDK_x - CaSDKObj.G_x) * (CaSDKObj.R_y - frmHelp.CASDK_y));
                Lb_t = 1.0;
                Lg_t = CaSDKObj.G_y * ((frmHelp.CASDK_y - CaSDKObj.R_y) * (CaSDKObj.B_x - frmHelp.CASDK_x) + (frmHelp.CASDK_x - CaSDKObj.R_x) * (frmHelp.CASDK_y - CaSDKObj.B_y)) / CaSDKObj.B_y / ((frmHelp.CASDK_y - CaSDKObj.R_y) * (frmHelp.CASDK_x - CaSDKObj.G_x) + (frmHelp.CASDK_x - CaSDKObj.R_x) * (CaSDKObj.G_y - frmHelp.CASDK_y));
                lumr = frmHelp.CASDK_LUM * Lr_t / (Lr_t + Lg_t + Lb_t);
                lumg = frmHelp.CASDK_LUM * Lg_t / (Lr_t + Lg_t + Lb_t);
                lumb = frmHelp.CASDK_LUM * Lb_t / (Lr_t + Lg_t + Lb_t);

                switch (index)
                {
                    case 0:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R255.Value = HX83200_R255.Value - step_h;
                                    else HX83200_R255.Value = HX83200_R255.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R255.Value = HX83200_R255.Value - step_l;
                                    else HX83200_R255.Value = HX83200_R255.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G255.Value = HX83200_G255.Value - step_h;
                                    else HX83200_G255.Value = HX83200_G255.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G255.Value = HX83200_G255.Value - step_l;
                                    else HX83200_G255.Value = HX83200_G255.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B255.Value = HX83200_B255.Value - step_h;
                                    else HX83200_B255.Value = HX83200_B255.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B255.Value = HX83200_B255.Value - step_l;
                                    else HX83200_B255.Value = HX83200_B255.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 1:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R252.Value = HX83200_R252.Value - step_h;
                                    else HX83200_R252.Value = HX83200_R252.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R252.Value = HX83200_R252.Value - step_l;
                                    else HX83200_R252.Value = HX83200_R252.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G252.Value = HX83200_G252.Value - step_h;
                                    else HX83200_G252.Value = HX83200_G252.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G252.Value = HX83200_G252.Value - step_l;
                                    else HX83200_G252.Value = HX83200_G252.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B252.Value = HX83200_B252.Value - step_h;
                                    else HX83200_B252.Value = HX83200_B252.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B252.Value = HX83200_B252.Value - step_l;
                                    else HX83200_B252.Value = HX83200_B252.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 2:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R248.Value = HX83200_R248.Value - step_h;
                                    else HX83200_R248.Value = HX83200_R248.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R248.Value = HX83200_R248.Value - step_l;
                                    else HX83200_R248.Value = HX83200_R248.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G248.Value = HX83200_G248.Value - step_h;
                                    else HX83200_G248.Value = HX83200_G248.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G248.Value = HX83200_G248.Value - step_l;
                                    else HX83200_G248.Value = HX83200_G248.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B248.Value = HX83200_B248.Value - step_h;
                                    else HX83200_B248.Value = HX83200_B248.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B248.Value = HX83200_B248.Value - step_l;
                                    else HX83200_B248.Value = HX83200_B248.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 3:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R244.Value = HX83200_R244.Value - step_h;
                                    else HX83200_R244.Value = HX83200_R244.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R244.Value = HX83200_R244.Value - step_l;
                                    else HX83200_R244.Value = HX83200_R244.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G244.Value = HX83200_G244.Value - step_h;
                                    else HX83200_G244.Value = HX83200_G244.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G244.Value = HX83200_G244.Value - step_l;
                                    else HX83200_G244.Value = HX83200_G244.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B244.Value = HX83200_B244.Value - step_h;
                                    else HX83200_B244.Value = HX83200_B244.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B244.Value = HX83200_B244.Value - step_l;
                                    else HX83200_B244.Value = HX83200_B244.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 4:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R236.Value = HX83200_R236.Value - step_h;
                                    else HX83200_R236.Value = HX83200_R236.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R236.Value = HX83200_R236.Value - step_l;
                                    else HX83200_R236.Value = HX83200_R236.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G236.Value = HX83200_G236.Value - step_h;
                                    else HX83200_G236.Value = HX83200_G236.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G236.Value = HX83200_G236.Value - step_l;
                                    else HX83200_G236.Value = HX83200_G236.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B236.Value = HX83200_B236.Value - step_h;
                                    else HX83200_B236.Value = HX83200_B236.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B236.Value = HX83200_B236.Value - step_l;
                                    else HX83200_B236.Value = HX83200_B236.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 5:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R228.Value = HX83200_R228.Value - step_h;
                                    else HX83200_R228.Value = HX83200_R228.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R228.Value = HX83200_R228.Value - step_l;
                                    else HX83200_R228.Value = HX83200_R228.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G228.Value = HX83200_G228.Value - step_h;
                                    else HX83200_G228.Value = HX83200_G228.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G228.Value = HX83200_G228.Value - step_l;
                                    else HX83200_G228.Value = HX83200_G228.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B228.Value = HX83200_B228.Value - step_h;
                                    else HX83200_B228.Value = HX83200_B228.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B228.Value = HX83200_B228.Value - step_l;
                                    else HX83200_B228.Value = HX83200_B228.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 6:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R220.Value = HX83200_R220.Value - step_h;
                                    else HX83200_R220.Value = HX83200_R220.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R220.Value = HX83200_R220.Value - step_l;
                                    else HX83200_R220.Value = HX83200_R220.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G220.Value = HX83200_G220.Value - step_h;
                                    else HX83200_G220.Value = HX83200_G220.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G220.Value = HX83200_G220.Value - step_l;
                                    else HX83200_G220.Value = HX83200_G220.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B220.Value = HX83200_B220.Value - step_h;
                                    else HX83200_B220.Value = HX83200_B220.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B220.Value = HX83200_B220.Value - step_l;
                                    else HX83200_B220.Value = HX83200_B220.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 7:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R212.Value = HX83200_R212.Value - step_h;
                                    else HX83200_R212.Value = HX83200_R212.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R212.Value = HX83200_R212.Value - step_l;
                                    else HX83200_R212.Value = HX83200_R212.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G212.Value = HX83200_G212.Value - step_h;
                                    else HX83200_G212.Value = HX83200_G212.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G212.Value = HX83200_G212.Value - step_l;
                                    else HX83200_G212.Value = HX83200_G212.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B212.Value = HX83200_B212.Value - step_h;
                                    else HX83200_B212.Value = HX83200_B212.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B212.Value = HX83200_B212.Value - step_l;
                                    else HX83200_B212.Value = HX83200_B212.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 8:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R204.Value = HX83200_R204.Value - step_h;
                                    else HX83200_R204.Value = HX83200_R204.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R204.Value = HX83200_R204.Value - step_l;
                                    else HX83200_R204.Value = HX83200_R204.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G204.Value = HX83200_G204.Value - step_h;
                                    else HX83200_G204.Value = HX83200_G204.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G204.Value = HX83200_G204.Value - step_l;
                                    else HX83200_G204.Value = HX83200_G204.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B204.Value = HX83200_B204.Value - step_h;
                                    else HX83200_B204.Value = HX83200_B204.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B204.Value = HX83200_B204.Value - step_l;
                                    else HX83200_B204.Value = HX83200_B204.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 9:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R196.Value = HX83200_R196.Value - step_h;
                                    else HX83200_R196.Value = HX83200_R196.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R196.Value = HX83200_R196.Value - step_l;
                                    else HX83200_R196.Value = HX83200_R196.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G196.Value = HX83200_G196.Value - step_h;
                                    else HX83200_G196.Value = HX83200_G196.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G196.Value = HX83200_G196.Value - step_l;
                                    else HX83200_G196.Value = HX83200_G196.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B196.Value = HX83200_B196.Value - step_h;
                                    else HX83200_B196.Value = HX83200_B196.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B196.Value = HX83200_B196.Value - step_l;
                                    else HX83200_B196.Value = HX83200_B196.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 10:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R188.Value = HX83200_R188.Value - step_h;
                                    else HX83200_R188.Value = HX83200_R188.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R188.Value = HX83200_R188.Value - step_l;
                                    else HX83200_R188.Value = HX83200_R188.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G188.Value = HX83200_G188.Value - step_h;
                                    else HX83200_G188.Value = HX83200_G188.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G188.Value = HX83200_G188.Value - step_l;
                                    else HX83200_G188.Value = HX83200_G188.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B188.Value = HX83200_B188.Value - step_h;
                                    else HX83200_B188.Value = HX83200_B188.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B188.Value = HX83200_B188.Value - step_l;
                                    else HX83200_B188.Value = HX83200_B188.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 11:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R180.Value = HX83200_R180.Value - step_h;
                                    else HX83200_R180.Value = HX83200_R180.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R180.Value = HX83200_R180.Value - step_l;
                                    else HX83200_R180.Value = HX83200_R180.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G180.Value = HX83200_G180.Value - step_h;
                                    else HX83200_G180.Value = HX83200_G180.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G180.Value = HX83200_G180.Value - step_l;
                                    else HX83200_G180.Value = HX83200_G180.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B180.Value = HX83200_B180.Value - step_h;
                                    else HX83200_B180.Value = HX83200_B180.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B180.Value = HX83200_B180.Value - step_l;
                                    else HX83200_B180.Value = HX83200_B180.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 12:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R164.Value = HX83200_R164.Value - step_h;
                                    else HX83200_R164.Value = HX83200_R164.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R164.Value = HX83200_R164.Value - step_l;
                                    else HX83200_R164.Value = HX83200_R164.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G164.Value = HX83200_G164.Value - step_h;
                                    else HX83200_G164.Value = HX83200_G164.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G164.Value = HX83200_G164.Value - step_l;
                                    else HX83200_G164.Value = HX83200_G164.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B164.Value = HX83200_B164.Value - step_h;
                                    else HX83200_B164.Value = HX83200_B164.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B164.Value = HX83200_B164.Value - step_l;
                                    else HX83200_B164.Value = HX83200_B164.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 13:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R148.Value = HX83200_R148.Value - step_h;
                                    else HX83200_R148.Value = HX83200_R148.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R148.Value = HX83200_R148.Value - step_l;
                                    else HX83200_R148.Value = HX83200_R148.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G148.Value = HX83200_G148.Value - step_h;
                                    else HX83200_G148.Value = HX83200_G148.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G148.Value = HX83200_G148.Value - step_l;
                                    else HX83200_G148.Value = HX83200_G148.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B148.Value = HX83200_B148.Value - step_h;
                                    else HX83200_B148.Value = HX83200_B148.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B148.Value = HX83200_B148.Value - step_l;
                                    else HX83200_B148.Value = HX83200_B148.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 14:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R132.Value = HX83200_R132.Value - step_h;
                                    else HX83200_R132.Value = HX83200_R132.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R132.Value = HX83200_R132.Value - step_l;
                                    else HX83200_R132.Value = HX83200_R132.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G132.Value = HX83200_G132.Value - step_h;
                                    else HX83200_G132.Value = HX83200_G132.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G132.Value = HX83200_G132.Value - step_l;
                                    else HX83200_G132.Value = HX83200_G132.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B132.Value = HX83200_B132.Value - step_h;
                                    else HX83200_B132.Value = HX83200_B132.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B132.Value = HX83200_B132.Value - step_l;
                                    else HX83200_B132.Value = HX83200_B132.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 15:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R116.Value = HX83200_R116.Value - step_h;
                                    else HX83200_R116.Value = HX83200_R116.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R116.Value = HX83200_R116.Value - step_l;
                                    else HX83200_R116.Value = HX83200_R116.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G116.Value = HX83200_G116.Value - step_h;
                                    else HX83200_G116.Value = HX83200_G116.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G116.Value = HX83200_G116.Value - step_l;
                                    else HX83200_G116.Value = HX83200_G116.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B116.Value = HX83200_B116.Value - step_h;
                                    else HX83200_B116.Value = HX83200_B116.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B116.Value = HX83200_B116.Value - step_l;
                                    else HX83200_B116.Value = HX83200_B116.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 16:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R100.Value = HX83200_R100.Value - step_h;
                                    else HX83200_R100.Value = HX83200_R100.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R100.Value = HX83200_R100.Value - step_l;
                                    else HX83200_R100.Value = HX83200_R100.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G100.Value = HX83200_G100.Value - step_h;
                                    else HX83200_G100.Value = HX83200_G100.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G100.Value = HX83200_G100.Value - step_l;
                                    else HX83200_G100.Value = HX83200_G100.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B100.Value = HX83200_B100.Value - step_h;
                                    else HX83200_B100.Value = HX83200_B100.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B100.Value = HX83200_B100.Value - step_l;
                                    else HX83200_B100.Value = HX83200_B100.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 17:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R84.Value = HX83200_R84.Value - step_h;
                                    else HX83200_R84.Value = HX83200_R84.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R84.Value = HX83200_R84.Value - step_l;
                                    else HX83200_R84.Value = HX83200_R84.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G84.Value = HX83200_G84.Value - step_h;
                                    else HX83200_G84.Value = HX83200_G84.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G84.Value = HX83200_G84.Value - step_l;
                                    else HX83200_G84.Value = HX83200_G84.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B84.Value = HX83200_B84.Value - step_h;
                                    else HX83200_B84.Value = HX83200_B84.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B84.Value = HX83200_B84.Value - step_l;
                                    else HX83200_B84.Value = HX83200_B84.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 18:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R68.Value = HX83200_R68.Value - step_h;
                                    else HX83200_R68.Value = HX83200_R68.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R68.Value = HX83200_R68.Value - step_l;
                                    else HX83200_R68.Value = HX83200_R68.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G68.Value = HX83200_G68.Value - step_h;
                                    else HX83200_G68.Value = HX83200_G68.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G68.Value = HX83200_G68.Value - step_l;
                                    else HX83200_G68.Value = HX83200_G68.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B68.Value = HX83200_B68.Value - step_h;
                                    else HX83200_B68.Value = HX83200_B68.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B68.Value = HX83200_B68.Value - step_l;
                                    else HX83200_B68.Value = HX83200_B68.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 19:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R52.Value = HX83200_R52.Value - step_h;
                                    else HX83200_R52.Value = HX83200_R52.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R52.Value = HX83200_R52.Value - step_l;
                                    else HX83200_R52.Value = HX83200_R52.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G52.Value = HX83200_G52.Value - step_h;
                                    else HX83200_G52.Value = HX83200_G52.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G52.Value = HX83200_G52.Value - step_l;
                                    else HX83200_G52.Value = HX83200_G52.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B52.Value = HX83200_B52.Value - step_h;
                                    else HX83200_B52.Value = HX83200_B52.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B52.Value = HX83200_B52.Value - step_l;
                                    else HX83200_B52.Value = HX83200_B52.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 20:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R44.Value = HX83200_R44.Value - step_h;
                                    else HX83200_R44.Value = HX83200_R44.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R44.Value = HX83200_R44.Value - step_l;
                                    else HX83200_R44.Value = HX83200_R44.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G44.Value = HX83200_G44.Value - step_h;
                                    else HX83200_G44.Value = HX83200_G44.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G44.Value = HX83200_G44.Value - step_l;
                                    else HX83200_G44.Value = HX83200_G44.Value + step_l;
                                }
                                adjust_Gnum++;
                            }

                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B44.Value = HX83200_B44.Value - step_h;
                                    else HX83200_B44.Value = HX83200_B44.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B44.Value = HX83200_B44.Value - step_l;
                                    else HX83200_B44.Value = HX83200_B44.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 21:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R36.Value = HX83200_R36.Value - step_h;
                                    else HX83200_R36.Value = HX83200_R36.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R36.Value = HX83200_R36.Value - step_l;
                                    else HX83200_R36.Value = HX83200_R36.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G36.Value = HX83200_G36.Value - step_h;
                                    else HX83200_G36.Value = HX83200_G36.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G36.Value = HX83200_G36.Value - step_l;
                                    else HX83200_G36.Value = HX83200_G36.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B36.Value = HX83200_B36.Value - step_h;
                                    else HX83200_B36.Value = HX83200_B36.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B36.Value = HX83200_B36.Value - step_l;
                                    else HX83200_B36.Value = HX83200_B36.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 22:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R28.Value = HX83200_R28.Value - step_h;
                                    else HX83200_R28.Value = HX83200_R28.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R28.Value = HX83200_R28.Value - step_l;
                                    else HX83200_R28.Value = HX83200_R28.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G28.Value = HX83200_G28.Value - step_h;
                                    else HX83200_G28.Value = HX83200_G28.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G28.Value = HX83200_G28.Value - step_l;
                                    else HX83200_G28.Value = HX83200_G28.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B28.Value = HX83200_B28.Value - step_h;
                                    else HX83200_B28.Value = HX83200_B28.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B28.Value = HX83200_B28.Value - step_l;
                                    else HX83200_B28.Value = HX83200_B28.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 23://20阶以下
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R20.Value = HX83200_R20.Value - step_h;
                                    else HX83200_R20.Value = HX83200_R20.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R20.Value = HX83200_R20.Value - step_l;
                                    else HX83200_R20.Value = HX83200_R20.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G20.Value = HX83200_G20.Value - step_h;
                                    else HX83200_G20.Value = HX83200_G20.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G20.Value = HX83200_G20.Value - step_l;
                                    else HX83200_G20.Value = HX83200_G20.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B20.Value = HX83200_B20.Value - step_h;
                                    else HX83200_B20.Value = HX83200_B20.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B20.Value = HX83200_B20.Value - step_l;
                                    else HX83200_B20.Value = HX83200_B20.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 24:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R16.Value = HX83200_R16.Value - step_h;
                                    else HX83200_R16.Value = HX83200_R16.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R16.Value = HX83200_R16.Value - step_l;
                                    else HX83200_R16.Value = HX83200_R16.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G16.Value = HX83200_G16.Value - step_h;
                                    else HX83200_G16.Value = HX83200_G16.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G16.Value = HX83200_G16.Value - step_l;
                                    else HX83200_G16.Value = HX83200_G16.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B16.Value = HX83200_B16.Value - step_h;
                                    else HX83200_B16.Value = HX83200_B16.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B16.Value = HX83200_B16.Value - step_l;
                                    else HX83200_B16.Value = HX83200_B16.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 25:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R12.Value = HX83200_R12.Value - step_h;
                                    else HX83200_R12.Value = HX83200_R12.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R12.Value = HX83200_R12.Value - step_l;
                                    else HX83200_R12.Value = HX83200_R12.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G12.Value = HX83200_G12.Value - step_h;
                                    else HX83200_G12.Value = HX83200_G12.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G12.Value = HX83200_G12.Value - step_l;
                                    else HX83200_G12.Value = HX83200_G12.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B12.Value = HX83200_B12.Value - step_h;
                                    else HX83200_B12.Value = HX83200_B12.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B12.Value = HX83200_B12.Value - step_l;
                                    else HX83200_B12.Value = HX83200_B12.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 26:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R8.Value = HX83200_R8.Value - step_h;
                                    else HX83200_R8.Value = HX83200_R8.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R8.Value = HX83200_R8.Value - step_l;
                                    else HX83200_R8.Value = HX83200_R8.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G8.Value = HX83200_G8.Value - step_h;
                                    else HX83200_G8.Value = HX83200_G8.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G8.Value = HX83200_G8.Value - step_l;
                                    else HX83200_G8.Value = HX83200_G8.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B8.Value = HX83200_B8.Value - step_h;
                                    else HX83200_B8.Value = HX83200_B8.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B8.Value = HX83200_B8.Value - step_l;
                                    else HX83200_B8.Value = HX83200_B8.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                    case 27:
                        {
                            if (flag3 == 1)
                            {
                                if (adjust_Rnum > 10)
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R4.Value = HX83200_R4.Value - step_h;
                                    else HX83200_R4.Value = HX83200_R4.Value + step_h;
                                    adjust_Rnum = 0;
                                    adjust_x++;
                                    if (adjust_x > 50)
                                    {
                                        x_off += 0.0005;
                                        adjust_x = 0;
                                    }
                                }
                                else
                                {
                                    if (lumr > D_lums[index, 0])
                                        HX83200_R4.Value = HX83200_R4.Value - step_l;
                                    else HX83200_R4.Value = HX83200_R4.Value + step_l;
                                }
                                adjust_Rnum++;
                            }
                            if (flag1 == 1)
                            {
                                if (adjust_Gnum > 10)
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G4.Value = HX83200_G4.Value - step_h;
                                    else HX83200_G4.Value = HX83200_G4.Value + step_h;
                                    adjust_Gnum = 0;
                                    adjust_l++;
                                    if (adjust_l > 50)
                                    {
                                        lum_off *= 1.5;
                                        adjust_l = 0;
                                    }
                                }
                                else
                                {
                                    if (lumg > D_lums[index, 1])
                                        HX83200_G4.Value = HX83200_G4.Value - step_l;
                                    else HX83200_G4.Value = HX83200_G4.Value + step_l;
                                }
                                adjust_Gnum++;
                            }
                            if (flag2 == 1)
                            {
                                if (adjust_Bnum > 10)
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B4.Value = HX83200_B4.Value - step_h;
                                    else HX83200_B4.Value = HX83200_B4.Value + step_h;
                                    adjust_Bnum = 0;
                                    adjust_y++;
                                    if (adjust_y > 50)
                                    {
                                        y_off += 0.0005;
                                        adjust_y = 0;
                                    }
                                }
                                else
                                {
                                    if (lumb > D_lums[index, 2])
                                        HX83200_B4.Value = HX83200_B4.Value - step_l;
                                    else HX83200_B4.Value = HX83200_B4.Value + step_l;
                                }
                                adjust_Bnum++;
                            }
                        }
                        break;
                }
                HX83200_GAMMA_Click(HX83200_GammaW_Red, e);
                HX83200_GAMMA_Click(HX83200_GammaW_Green, e);
                HX83200_GAMMA_Click(HX83200_GammaW_Blue, e);
            }
        }

        private void HX83200_Gamma_Load(object sender, EventArgs e)
        {

        }
    }
}
